package asteroids.expressions;

import be.kuleuven.cs.som.annotate.Basic;

public abstract class BinaryExpression extends ComposedExpression {
	
	private Expression firstExpression;
	private Expression secondExpression;
	
	protected BinaryExpression(int line, int column, Expression e1, Expression e2) {
		super(line, column);
		this.firstExpression = e1;
		this.secondExpression = e2;
	}

	@Basic
	public Expression getFirstExpression() {
		return firstExpression;
	}
	
	@Basic
	public Expression getSecondExpression() {
		return secondExpression;
	}

	@Override
	public int getNbExpressions() {
		return 2;
	}

	@Override
	public Expression getExpressionAt(int index) throws IndexOutOfBoundsException {
		if ((index != 1) && (index != 2))
			throw new IndexOutOfBoundsException();
		if (index == 1)
			return getFirstExpression();
		else
			return getSecondExpression();
	}
	
}
